<template>
  <div v-if="isShow" class="container">
    <el-row class="row-bg" type="flex">
      <el-col :span="6">
        <div class="grid-content bg-purple">【题型】：{{ list.data.questionType=='1'?'单选题':list.data.questionType=='2'?'多选题':'简答题' }}</div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content bg-purple">【编号】：{{ list.data.id }}</div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content bg-purple">【难度】：{{ list.data.difficulty=='1'?'简单':list.data.difficulty=='2'?'中等':'困难' }}</div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content bg-purple">【标签】：{{ list.data.tags }}</div>
      </el-col>
    </el-row>
    <el-row class="row-bg2" type="flex">
      <el-col :span="6">
        <div class="grid-content bg-purple">【学科】：{{ list.data.subjectName }}</div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content bg-purple">【目录】：{{ list.data.directoryName }}</div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content bg-purple">【方向】：{{ list.data.direction }}</div>
      </el-col>
    </el-row>
    <hr>
    <el-row class="row-bg2" type="flex">
      <el-col :span="12">
        <div class="grid-content bg-purple">【题干】：</div>
        <p :style="{color:'blue'}" v-html="list.data.question" />
        <p>{{ list.data.questionType=='1'?'单选题':list.data.questionType=='2'?'多选':'答题' }} 选项：（以下选中的选项为正确答案）</p>
      </el-col>
    </el-row>
    <!-- 单选 -->
    <template v-if="list.data.questionType==1">
      <el-radio v-model="radio" class="select" label="A">{{ list.data.options[0].title }}</el-radio>
      <br>
      <el-radio v-model="radio" class="select" label="B">{{ list.data.options[1].title }}</el-radio>
      <br>
      <el-radio v-model="radio" class="select" label="C">{{ list.data.options[2].title }}</el-radio>
      <br>
      <el-radio v-model="radio" class="select" label="D">{{ list.data.options[3].title }}</el-radio>
      <br>
    </template>
    <!-- 多选 -->
    <template v-if="list.data.questionType==2">
      <el-checkbox-group v-model="checkedAnswer">
        <el-checkbox v-for="item in list.data.options" :key="item.title" :label="item.code" class="select">{{ item.title }}</el-checkbox>
        <br>
      </el-checkbox-group>
    </template>
    <!-- 简答题 -->
    <template v-if="list.data.questionType==3">
      <el-input v-model="textarea" :rows="2" placeholder="请输入内容" type="textarea" />
    </template>
    <hr>
    <!-- 视频答案 -->
    <el-row class="row-bg3" type="flex">
      <el-col :span="12">
        <div class="grid-content bg-purple">
          【参考答案】：
          <el-button type="danger" @click="videoShow=!videoShow">视频答案预览</el-button>
          <video v-if="videoShow" :src="`https://tucdn.wpon.cn/api-girl/videos/${num}.mp4`" autoplay controls height="300" width="400" />
        </div>
      </el-col>
    </el-row>
    <hr>
    <el-row class="row-bg4" type="flex">
      <el-col>
        <div class="grid-content bg-purple" v-html="'【答案解析】：'+ list.data.answer" />
      </el-col>
    </el-row>
    <hr>
    <el-row class="row-bg5" type="flex">
      <el-col>
        <div class="grid-content bg-purple" v-html="'【题目备注】：'+ list.data.remarks" />
      </el-col>
    </el-row>
    <el-row justify="end" type="flex">
      <el-col :span="3">
        <el-button class="close" type="primary" @click="$emit('showCodeDialog',false)">关闭</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { detail } from '@/api/hmmm/questions'
export default {
  data() {
    return {
      radio: 'A', // 单选默认  单选题答案
      list: [], // 框架数据
      chooseSingle: false, // 单选框的展示
      chooseMore: false, // 多选框的展示
      simpleQuestion: false, // 简答题
      videoShow: false, // 视频解析显示
      checked: false, // 当前是否勾选
      isShow: false, // 数据框请求后展示
      checkedAnswer: [], // 多选题答案
      textarea: '', // 简答题答案
      num: Math.floor(Math.random() * 140)
    }
  },
  watch: {
    // 这里解决数据上来出现underfind问题
    list() {
      if (this.list !== []) {
        this.isShow = true
        this.getAnswer()
      }
    }
  },

  methods: {
    async detail(data) {
      // 请求详细数据
      try {
        this.list = await detail(data)
      } catch (error) {
        this.$message.error('数据请求失败')
      }
    },
    getAnswer() {
      // 单选题答案
      const options = this.list.data.options
      if (this.list.data.questionType == 1) {
        options.forEach((item) => {
          if (item.isRight === 1) {
            this.radio = item.code
          }
        })
        // 多选题答案
      } else if (this.list.data.questionType == 2) {
        options.forEach((item) => {
          if (item.isRight === 1) {
            this.checkedAnswer.push(item.code)
          }
        })
      } else {
        this.textarea = '是的,PHP是世界上最好的语言。这是网络上广泛流传的一个梗,并不是说PHP就真的是编程最好的语言,其实每款编程语言都有自身的优势以及所专长的领域,并不能简单地说PHP就是最好的编程语言,这多少有点调侃的成分。'
      }
    }
  }
}
</script>

<style scoped lang='scss'>
.container {
    .row-bg {
        padding-bottom: 20px;
    }
    .row-bg2 {
        padding-bottom: 10px;
    }
    .row-bg5 {
        padding-bottom: 20px;
    }
    .select {
        padding-bottom: 10px;
    }
}
</style>
